package com.xbongbong.saas.domain.dao;

import com.xbongbong.saas.domain.entity.BusinessProductEntity;
import com.xbongbong.saas.domain.entity.OutstockProductEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author Jian.Wang
 * @version v1.0
 * @date 2019/2/21 14:35
 * @since v1.0
 */
@Mapper
@Repository
public interface OutstockProductDao {
    /**
     * 插入数据
     *
     * @param outstockProduct 入库单产品实体数据
     * @return 是否成功
     * @author Jian.Wang
     * @date 2019/2/21 15:18
     **/
    Integer insert(OutstockProductEntity outstockProduct);
    /**
     * 更新数据
     *
     * @param outstockProduct 入库单产品实体数据
     * @return 是否成功
     * @author Jian.Wang
     * @date 2019/2/21 15:18
     **/
    Integer update(OutstockProductEntity outstockProduct);
    /**
     * 根据主键删除记录
     *
     * @param key    主键
     * @param corpid 公司id
     * @return java.lang.Integer
     * @author Jian.Wang
     * @date 2019/2/21 15:18
     */
    Integer deleteByKey(@Param("key") Long key, @Param("corpid") String corpid);
    /**
     * 删除多条入库单下的所有产品
     *
     * @param corpid    公司ID
     * @param outstockIdIn 入库单Id集合
     * @param corpid 公司id
     * @return java.lang.Integer
     * @author Jian.Wang
     * @date 2019/2/21 15:18
     */
    Integer deleteByOutstockIdIn(@Param("corpid") String corpid, @Param("outstockIdIn") List<Long> outstockIdIn);
    /**
     * 删除入库单下的所有产品
     *
     * @param refId    id集合
     * @param corpid 公司id
     * @return java.lang.Integer
     * @author Jian.Wang
     * @date 2019/2/21 15:18
     */
    Integer deleteByOutstockId(@Param("refId") Long refId, @Param("corpid") String corpid);
    /**
     * 获取一条入库单产品数据
     *
     * @param key 采购合同产品ID
     * @param corpid 公司id
     * @return OutstockProductEntity 一条数据实体
     * @author Jian.Wang
     * @date 2019/2/21 15:18
     */
    OutstockProductEntity getByKey(@Param("key") Long key, @Param("corpid") String corpid);
    /**
     * 多参数查询多条数据
     *
     * @param param 参数集合
     * @return List<OutstockProductEntity> 数据集合
     * @author Jian.Wang
     * @date 2019/2/21 15:18
     */
    List<OutstockProductEntity> findEntitys(@Param("param") Map<String, Object> param);
    /**
     * 模糊查询
     *
     * @param corpid 参数集合
     * @param nameOrNoLike 模糊查询值
     * @return List<Long> 数据集合
     * @author Jian.Wang
     * @date 2019/2/21 15:18
     */
    List<Long> findOutstockIdsByRelaProNameOrNo(String corpid, String nameOrNoLike);
    /**
     * 获取记录数
     *
     * @param param 参数集合
     * @return  Integer Id集合
     * @author Jian.Wang
     * @date 2019/2/21 15:18
     */
    Integer getEntitysCount(@Param("param") Map<String, Object> param);
    /**
     * 获取产品总销量
     * @param param
     * @return java.lang.Double
     * @author zcp
     * @date 2019/4/16 10:22
     * @since v1.0
     * @version v1.0
     */
    Double getProductNumSum(@Param("param") Map<String ,Object>  param);

    Integer deleteBatchById(@Param("idIn") Collection<Long> delOutstockProductIdList, @Param("corpid") String corpid, @Param("del") Integer del);


    void insertBatch(@Param("list") List<OutstockProductEntity> addOutstockProductEntityList);

    void updateOutBatch(@Param("list") List<OutstockProductEntity> updateBatchList, @Param("corpid") String corpid);

    List<BusinessProductEntity> findProductNum(@Param("param") Map<String,Object> param);

    Integer findProductNumCount(@Param("param") Map<String,Object> param);

    Integer updateBatch(@Param("list") List<OutstockProductEntity> updateList, @Param("corpid") String corpid);

    Long isProductSubAttrExist(@Param("attr") String attr, @Param("corpid") String corpid, @Param("formId") Long formId,@Param("isArray") Integer isArray);

    List<OutstockProductEntity> findForJob();

    OutstockProductEntity getProductsByInstockIdAndRefProductId(@Param("outstockId") Long outstockId, @Param("refProductId") Long refProductId, @Param("corpid") String corpid);

    Double summaryByAttr(@Param("field")  String field,@Param("corpid") String corpid,@Param("refId")  Long refId, @Param("productIdIn") List<Long> productIdIn);

    Double summaryByAttrContractOutStock(@Param("field")  String field,@Param("corpid") String corpid,@Param("refId")  Long refId, @Param("productIdIn") List<Long> productIdIn);

    Double summaryByAttrFromOutSide(@Param("field")  String field,@Param("corpid") String corpid,@Param("refId")  Long refId, @Param("productIdIn") List<Long> productIdIn);

    Integer dataConsistencyUpdate(@Param("corpid") String corpid, @Param("productId") Long productId, @Param("productName") String productName, @Param("specification") String specification, @Param("productNo") String productNo);


    Long countProductSub(@Param("attr") String attr, @Param("corpid") String corpid, @Param("formId") Long formId, @Param("isArray") Integer isArray);

    List<OutstockProductEntity> getProductWithSubData(@Param("attr") String attr, @Param("corpid") String corpid, @Param("formId") Long formId, @Param("isArray") Integer isArray, @Param("idGte") Long idGte, @Param("limit") Integer limit);

    /**
     * 批量编辑
     * @param list
     * @param corpid
     * @return java.lang.Integer
     * @author 吴峰
     * @date 2021/7/27 10:58
     * @throws
     */
    Integer updateMulti(@Param("list")List<OutstockProductEntity> list, @Param("corpid") String corpid);

    void updateOutstockProductById(@Param("list")List<OutstockProductEntity> outstockProductEntityList, @Param("corpid")String corpid);

    List<OutstockProductEntity> getOutstockProductById(@Param("list")List<Long> outstockProductId, @Param("corpid")String corpid);

    List<OutstockProductEntity> getOutstockProductByRefId(@Param("list")List<Long> refId, @Param("corpid")String corpid);

    List<OutstockProductEntity> getOrderOutStockData(@Param("refId") Long refId, @Param("corpid") String corpid);

    OutstockProductEntity getOutstockProductSum(@Param("param")Map<String, Object> map);

    Set<Long> getWarehouseIdUnion(@Param("warehouseIdList") Set<Long> warehouseIdList, @Param("corpid") String corpid);
}
